package cn.com.api.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiTags;
import cn.com.api.service.ApiTagsService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "tags/")
public class ApiTagsController {
	@Autowired
	private ApiTagsService apiTagsService;

	/**
	 * 条件查询对关键字列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/getTopTags")
	public void getTopTags(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String limit = request.getParameter("limit");
		List<ApiTags> datas = apiTagsService
				.getTopTags(Integer.parseInt(limit));
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
		map.put("datas", datas);
		out.print(JsonUtil.object2json(map));
		out.close();
	}
}
